<template>
  <div>
    <h1>创新</h1>
    <!-- 去注册页面 -->
    <button @click="goRegister">go register</button>
    <!-- 去登陆页面 -->
    <button @click="goLogin">go login</button>

    <button @click="testGo">test go</button>
  </div>
</template>

<script>
export default {
  name: "",
  props: [""],
  data() {
    return {
      info: "注意编辑器自动形成一些不需要的代码",
    };
  },

  components: {},

  computed: {},

  beforeMount() {},

  mounted() {},

  methods: {
    goRegister() {
      console.log(this.$router);
      this.$router.push("/register");
    },
    goLogin() {
      this.$router.push("/login");
    },
    testGo() {
      this.$router.go(-1);
    },
  },

  watch: {},
  // 组件守卫 ：只针对当前路由组件   进入 更新 离开  beforRouteEnter beforeRouteUpdate  beforeRouteLeave
  beforeRouteEnter(to, from, next) {
    console.log(to);
    console.log(from);
    // console.log(this); //组件守卫中 进入组件前beforeRouteEnter,还未进入，this指向undefined 不指向当前组件对象4
    // next();
    // next("/login");
    // let num = -1; //注意一下小细节
    /* if (num > 0) {
      next("/login");
    } else {
      next("/register");
    } */

    next((component) => {
      // components指向当前组件对象
      console.log(component);
    });
  },
  // 离开组件时触发的事件
  beforeRouteLeave(to, from, next) {
    console.log(this);
    console.log(to);
    console.log(from);
    next();
  },
};
</script>
<style lang='' scoped>
</style>